<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      body {
        display: flex;
        justify-content: space-around;
      }
      span {
        margin-right: 10px;
        border: 1px solid rgb(190, 38, 38);
        cursor: pointer;
      }
      section {
        width: 200px;
        height: 200px;
        background-color: rgb(170, 170, 58);
        margin-top: 30px;
      }
      a {
        display: block;
        width: 100px;
        text-align: center;
        height: 30px;
        border: 1px solid #632cf6;
        background-color: #95a5a6;
      }
    </style>
  </head>
  <body>
    <main class="tab1">
      <nav>
        <a href="javascript:;">后盾人</a>
        <a href="javascript:;">jdcms</a>
      </nav>

      <section>1</section>
      <section>2</section>
    </main>

    <main class="tab2">
      <nav>
        <a href="javascript:;">后盾人</a>
        <a href="javascript:;">jdcms</a>
      </nav>

      <section>1</section>
      <section>2</section>
    </main>
  </body>
</html>

<script>
  function extend(sub, sup) {
    sub.prototype = Object.create(sup.prototype);
    sub.prototype.constructor = sub;
  }

  function Animation() {}
  Animation.prototype.show = function () {
    this.style.display = "block";
  };

  Animation.prototype.hide = function () {
    this.style.display = "none";
  };

  Animation.prototype.background = function (color) {
    this.style.backgroundColor = color;
  };

  function Tab(el) {
    this.tab = document.querySelector(el);

    this.links = this.tab.querySelectorAll("a");

    this.sections = this.tab.querySelectorAll("section");
  }

  extend(Tab, Animation);
  Tab.prototype.run = function () {
    this.bindEvent();
    this.reset();
    this.action(0);
  };

  Tab.prototype.bindEvent = function () {
    this.links.forEach((el, i) => {
      el.addEventListener("click", () => {
        this.reset();
        this.action(i);
      });
    });
  };

  Tab.prototype.action = function (i) {
    this.background.call(this.links[i], "#e67e22");
    this.show.call(this.sections[i]);
  };

  Tab.prototype.reset = function () {
    this.links.forEach((el, i) => {
      this.background.call(this.links[i], "#95a5e6");
      this.hide.call(this.sections[i]);
    });
  };

  new Tab(".tab2").run();
</script>
